﻿using System;
using System.Data;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using Telerik.Web.UI;
using KPIS.GERP.GHRMS.BLL;
using KPIS.GERP.GHRMS.IBLL;
using KPIS.GERP.GHRMS.MODEL;
using KPIS.Utils;

namespace KPIS.GERP.GHRMS.APP.App_UI.Forms
{
    public partial class WF_ProjectLoan : System.Web.UI.Page
    {
        private SsMng ssMng = new SsMng();

        protected void Page_Load(object sender, EventArgs e)
        {
            IncludeJava();
            if (!IsPostBack)
            {
                Session["finance_seq"] = Request.QueryString["id"];
                lblFinanceName.Text = Request.QueryString["Name"].ToString();
                LoadDataGrid();
            }
        }

        private void LoadDataGrid()
        {
            DataTable dt;
            WelfareFinanceBLL obj = new WelfareFinanceBLL();

            int finance_seq = int.Parse(Session["finance_seq"].ToString());

            dt = obj.SelectLoan(finance_seq);

            RadGrid2.DataSource = dt;
            RadGrid2.DataBind();
         
        }

        public void IncludeJava()
        {
            HtmlGenericControl script = new HtmlGenericControl();
            script.TagName = "script";
            script.Attributes.Add("type", "text/javascript");
            script.Attributes.Add("src", "../../Scripts/jsfunction.js");
            Page.Header.Controls.Add(script);
        }

        protected void RadGrid2_ItemCommand(object source, GridCommandEventArgs e)
        {
            try
            {

                if (e.CommandName == "btnClick")
                    return;

                if (e.CommandName == "Delete")
                {
                    int seq = Convert.ToInt32((e.Item as GridDataItem).OwnerTableView.DataKeyValues[e.Item.ItemIndex]["loan_seq"]);

                    WelfareFinanceBLL obj = new WelfareFinanceBLL();
                    obj.DeleteLoan(seq, ssMng.EmpSeqI);
                }
                LoadDataGrid();

            }
            catch (Exception ex)
            {
                Web.ShowAlert(this, ex.Message);
            }


        }
        
    }

}